﻿using Cherry.Agile.Data.Object.Metadata;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Cherry.Agile.Data.Metadata
{
    internal sealed class InsertExpressionParser<T> : DmlExpressionParser<T>
        where T : class
    {
        private Expression insertParser;

        public InsertExpressionParser(string containerName, Expression<Func<T, T>> inserter)
            : base(containerName)
        {
            insertParser = inserter;
        }

        public override string GetDmlCommand()
        {
           // StringBuilder insertCommand = new StringBuilder();
           //// insertCommand.Append("INSERT INTO ");
           // //insertCommand.Append(MetadataAccessor.GetTableNameByEdmType<T>(containerName).TableName);
           // var InsertMemberExpr = (MemberInitExpression)insertParser.Body;
           // // System.Linq.Expressions.
           // var InsertMemberCollection = InsertMemberExpr.Bindings.Cast<MemberAssignment>().Select(c => new
           // {
           //     Name = c.Member.Name,
           //     Value = Expression.Lambda(c.Expression, null).Compile().DynamicInvoke()
           // });

           // int i = 0;
           // string Table = MetadataAccessor.GetTableNameByEdmType<T>(containerName).TableName;
           // string InsertField = string.Join(", ", InsertMemberCollection.Select(c => string.Format("[{0}]", c.Name)).ToArray());
           // string sqlInsertValue = string.Join(", ", InsertMemberCollection.Select(c => string.Format("{0}", "{" + (i++) + "}")).ToArray());
           // string commandText = string.Format("insert into [{0}]({1}) values({2}) ", Table, InsertField, sqlInsertValue);
           // //获取SQL参数数组 (包括查询参数和赋值参数)
           // var args = InsertMemberCollection.Select(c => c.Value).ToArray();
            return string.Empty;
        }
    }
}
